import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex); // vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
  state: {
    //存放状态
    shoppingCart: [],
  },
  mutations: {
    ADD_SHOPPING_CART(state, data) {
      state.shoppingCart.push({
        ...data,
        id: Date.now(),
      });
    },
  },
  actions: {
    addShoppingCart({ commit }, data) {
      commit("ADD_SHOPPING_CART", {
        ...data,
        quantity: 1,
        checked: false,
      });
    },
  },
});
export default store;
